@ECHO OFF
SET MYSELF="%~n0.BAT"
SET CUR_PATH="%~dp0"
SET TARGET_PATH=%CUR_PATH%

SET YYYY=%DATE:~-10,4%
SET MM=%DATE:~-5,2%
SET DD=%DATE:~-2,2%
SET TODAY=%YYYY%%MM%%DD%
SET HH=%TIME:~0,2%
SET HH=%HH: =0%
SET MI=%TIME:~3,2%
SET SS=%TIME:~6,2%
SET TIMESTAMP=%YYYY%%MM%%DD%%HH%%MI%%SS%

SET COUNT=0

IF "%1" NEQ "" SET CUR_PATH=%1
IF "%2" NEQ "" SET TARGET_PATH=%2

PUSHD %TARGET_PATH%
	MD %TIMESTAMP%
POPD


PUSHD %CUR_PATH%
	FOR %%f IN ( * ) DO (
		IF /I "%%f" NEQ %MYSELF% (
			CALL :__MOVE_FILES__ "%%f" %CUR_PATH% %TARGET_PATH%\%TIMESTAMP%
		)
	)
	FOR /D %%d IN ( * ) DO (
		IF "%%d" NEQ "%TIMESTAMP%" (
			CALL :__MOVE_FILES__ "%%d" %CUR_PATH% %TARGET_PATH%\%TIMESTAMP%
		)
	)
	IF %COUNT% EQU 0 RD /S /Q %TIMESTAMP%
POPD


EXIT /B


:__MOVE_FILES__
	PUSHD %2
		MOVE /Y %1 %3\
	POPD
	SET /A COUNT=%COUNT%+1
EXIT /B

